﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ClassLibrarySample
{
    public delegate void EightBallMessageHandler(object sender, EventArgs e);

    public class EightBall
    {
        List<string> Messages = new List<string>();

        private string message = string.Empty;
        public string Message
        {
            get { return message; }
        }

        public EightBall()
        {
            Messages.Add("Yes");
            Messages.Add("No");
            Messages.Add("Maybe");
            Messages.Add("Beats Me");
            Messages.Add("Ask later");
            Messages.Add("Absolutely Not");
            Messages.Add("Absolutely");
            Messages.Add("Use the force");
        }

        public event EightBallMessageHandler EightBallMessageReady;

        public void Shake()
        {
            message = "Thinking...";
            if (EightBallMessageReady != null)
            {
                EightBallMessageReady(this, EventArgs.Empty);
            }

            Random rand = new Random();
            int messageNumber = rand.Next(0, Messages.Count);

            message = Messages[messageNumber];

            if (EightBallMessageReady != null)
            {
                System.Threading.Thread.Sleep(rand.Next(1000, 5000));
                EightBallMessageReady(this, EventArgs.Empty);
            }
        }
    }
}
